import { Injectable } from '@angular/core';
import {ExtendHttpService} from "../../common/extend-http.service";
import {SocketService} from "../services/socket.service";
import {TipService} from "../services/tip.service";
import {Router} from "@angular/router";

@Injectable()
export class EssService {

  showBtns: any = [];

  constructor(public sockets: SocketService, private ext: ExtendHttpService, private tips: TipService, private router: Router) { }

  // 获取登录人信息-按钮权限
  getLoginInfo() {
    this.ext.post('/merchantApp/basics/loginInfo/getInfo', {}).subscribe(res => {
      if (res.json().code === '0') {
        this.showBtns = [];
        let arr = res.json().merchantAppMenu;
        for (let i in arr) {
          this.showBtns.push(arr[i].code);
        }
        // console.log(this.showBtns);
      } else {
        this.tips.change(true, res.json().message);
      }
    });
  }

  // 请求错误信息提示2
  errTips(data) {
    let tips = data.message;
    if (data.code === '-2001') {
      tips = '您没有登录，无法操作';
      this.router.navigateByUrl('login');
    }
    return tips;
  }

}
